package com.example.proyyj.Controller;

import com.example.proyyj.Entity.Chinaware;
import com.example.proyyj.Entity.Newss;
import com.example.proyyj.Entity.ResultEntity;
import com.example.proyyj.Service.ChinaService;
import com.example.proyyj.Util.JSONTool;
import com.example.proyyj.tool.JsonUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/Chinaware")
public class ChinawareController {
    ResultEntity resultEntity=null;
    @Resource
    ChinaService chinaService;

    /**
     * 查询所有陶瓷
     * @param
     * @return
     */
    @GetMapping("getChinawareList")
    private  String chinaware(){

        try {
            resultEntity=new ResultEntity();
            List<Chinaware> list=chinaService.getChinawareList();
            if (list!=null){
                resultEntity.setCode("0");
                resultEntity.setMsg("查询成功");
                resultEntity.setCount(list.size());
                resultEntity.setData(list);
            }
        }catch (Exception e){
            e.printStackTrace();
            resultEntity.setCode("99999");
            resultEntity.setMsg("查询失败"+e.getMessage());
        }
        return  JSONTool.getJsonTool().toJson(resultEntity);
    }
    /**
     * 根据id查询陶瓷
     */
    @GetMapping ("getChinawareById")
    private  String chinaware(@RequestParam("id") int id){


        resultEntity=new ResultEntity();
        try{
            Chinaware chinaware=chinaService.getChinawareId(id);
            if (id!=0){
                resultEntity.setCode("0");
                resultEntity.setMsg("查询成功");
                resultEntity.setData(chinaware);
            }

        }catch (Exception e){
            e.printStackTrace();
            resultEntity.setCode("9999");
            resultEntity.setMsg("系统错误，请联系管理员");
        }
        return JsonUtil.getJsonTool().toJson(resultEntity);
    }
}
